package com.coconet.gas.constant;

public enum dwEnum {
	SUCCEESS(0, "Continue", "成功"),
	FAILURE(1, "Switching Protocols", "失败"),
	REQUESTERR(3,"Processing", "请求参数有问题"),
	FAILEDTASKS(6,"Processing", "请求参数有问题");
	private final int code;
	private final String reasonPhraseUS;
	private final String reasonPhraseCN;
	private static final int INFORMATIONAL = 1, SUCCESSFUL = 2, REDIRECTION = 3, CLIENT_ERROR = 4, SERVER_ERROR = 5;

	dwEnum(int code, String reasonPhraseUS, String reasonPhraseCN) {
    this.code = code;
    this.reasonPhraseUS = reasonPhraseUS;
    this.reasonPhraseCN = reasonPhraseCN;
}

	public int code() {
		return code;
	}

	public String reasonPhraseUS() {
		return reasonPhraseUS;
	}

	public String reasonPhraseCN() {
		return reasonPhraseCN;
	}

	public static dwEnum valueOf(int code) {
		for (dwEnum httpStatus : values()) {
			if (httpStatus.code() == code) {
				return httpStatus;
			}
		}
		throw new IllegalArgumentException("No matching constant for [" + code + "]");
	}

	public boolean is1xxInformational() {
		return type() == INFORMATIONAL;
	}

	public boolean is2xxSuccessful() {
		return type() == SUCCESSFUL;
	}

	public boolean is3xxRedirection() {
		return type() == REDIRECTION;
	}

	public boolean is4xxClientError() {
		return type() == CLIENT_ERROR;
	}

	public boolean is5xxServerError() {
		return type() == SERVER_ERROR;
	}

	private int type() {
		return (int) code / 100;
	}
}
